package peer.servertcp;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

import peer.Core;
import peer.rudp.command.TestSpeedCOM1;

public class TCPServerTest {
	
	public static void main(String[] args) {
		new TCPServerTest();
	}
	TCPServerTest() {
		//SourceServerTCP.init();
		
		
		try {
			ServerSocket ss=new ServerSocket(80);
			while(true){
				final Socket s=ss.accept();
				new Thread(){
					public void run(){
						OutputStream os;
						try {
							os = s.getOutputStream();
							byte[] data=new byte[1024*1000*10];
							try {
								os.write(getHreder().getBytes());
							while(true){
								os.write(data);
								System.out.println("send "+data.length);
							}} catch (IOException e) {
								e.printStackTrace();
							}
						} catch (IOException e1) {
							e1.printStackTrace();
						}
						
					}
				}.start();
				
			}
			
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}
	
	String getHreder(){
		String s2="HTTP/1.1 200 OK\r\n"
			+"Date: Sat, 13 Jun 2009 10:02:20 GMT\r\n"
			+"Content-Length: "+"8985622"+"\r\n"
			+"Server: Apache/2.0.63 (Win32) PHP/5.2.9-2\r\n"
			+"Connection: Keep-Alive\r\n"
			+"Content-Type: text/plain\r\n"
			+"Keep-Alive: timeout=15, max=100\r\n"
			+"ETag: \"3afb-2a153aa9-eae60d40\"\r\n"
			+"Accept-Ranges: bytes\r\n"
			+"\r\n";
		return s2;
	}

}
